package controllers

import (
	"fmt"
)

func josephus(n, m int) []int {
	// 初始化数组存储数字 1 到 n
	numbers := make([]int, n)
	for i := 0; i < n; i++ {
		numbers[i] = i + 1
	}

	var result []int
	index := 0

	for len(numbers) > 0 {
		// 找到当前要移除的数字的索引
		index = (index + m - 1) % len(numbers)
		// 将数字添加到结果中
		result = append(result, numbers[index])
		// 从原数组中移除该数字
		numbers = append(numbers[:index], numbers[index+1:]...)
	}

	return result
}

func main() {
	n, m := 5, 3
	result := josephus(n, m)
	fmt.Println("最终顺序:", result)
}
